package com.lancoo.znbkxx.teacher.ui.fragment.cognitiveAssessment

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod.addClickScale
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.MyToast
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.ui.fragment.cognitiveAssessment.secondView.AnalysisLanguageAbilityActivity
import kotlinx.android.synthetic.main.aibk_adapter_item_cognitive_infor.view.*

class CognitiveInforItemAdapter(
        val activity: FragmentActivity
):KBaseRecyclerAdapter(){

    var arryIcon = intArrayOf(R.mipmap.aibk_icon_ca_vocabulary_cognition, R.mipmap.aibk_icon_ca_grammar_cognition, R.mipmap.aibk_icon_ca_language_ability,
            R.mipmap.aibk_icon_ca_answer_trait, R.mipmap.aibk_icon_ca_study_time, R.mipmap.aibk_icon_ca_knowledge_coverage)
    val arryTitle = intArrayOf( R.string.tv_item_title_1,R.string.tv_item_title_2,R.string.tv_item_title_3,
            R.string.tv_item_title_4,R.string.tv_item_title_5,R.string.tv_item_title_6)
    val arryX = intArrayOf(R.string.tv_description_x1,R.string.tv_description_x2,R.string.tv_description_x3)
    val arryY = intArrayOf(R.string.tv_description_y1,R.string.tv_description_y2,R.string.tv_description_y3)
    val arryZ = intArrayOf(R.string.tv_description_z1,R.string.tv_description_z2,R.string.tv_description_z3)
    val arryW = intArrayOf(R.string.tv_description_w1,R.string.tv_description_w2,R.string.tv_description_w3)

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_cognitive_infor, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        val drawableDown = activity.resources.getDrawable(arryIcon[position])
        drawableDown.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
        holder.convertView.TvItemTitle.setCompoundDrawables(drawableDown,null,null,null)
        holder.convertView.TvItemTitle.text = activity.resources.getString(arryTitle[position])
        holder.convertView.RlItem.addClickScale()
        holder.convertView.RlItem.setOnClickListener {
            MyToast.showToast("点击了$position")
            AnalysisLanguageAbilityActivity.launch(activity)
        }

        if(position == 0) {
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryX[0])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
        }else if(position == 1){
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryX[1])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooGreen))
        }else if(position == 2){
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryX[2])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooOrange))
        }else if(position == 3){
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryY[0])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
        }else if(position == 4){
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryZ[1])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooGreen))
        }else if(position == 5){
            holder.convertView.TvItemDescription.text = activity.resources.getString(arryW[2])
            holder.convertView.TvItemDescription.setTextColor(activity.resources.getColor(R.color.lancoooOrange))
        }
    }

    override fun getItemCount(): Int {
        return 6
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }
}